<template>
  <canvas class="canvas" ref="chartRef"></canvas>
</template>
<script setup>
import { Chart, registerables } from 'chart.js'

// 注册所有 Chart.js 组件
Chart.register(...registerables)

const props = defineProps({
  options: Object,
})

const chartRef = ref()
let chart

onMounted(() => {
  iniChat()
})

onBeforeUnmount(() => {
  if (chartInstance) {
    chartInstance.destroy()
  }
})

function iniChat() {
  const ctx = chartRef.value.getContext('2d')

  const chart = new Chart(ctx, props.options)
}
</script>
<style lang="scss" scoped></style>
